﻿using System.Data;
using Rhino.Mocks;

namespace EventHandler.Libraries.Business.Tests
{
	internal static class MockUtilities
	{
		public static IDbCommand CreateMockCommand(IDbConnection cnn)
		{
			var command = MockRepository.GenerateMock<IDbCommand>();
			cnn.Expect(x => x.CreateCommand()).Return(command);
			command.Expect(x => x.CommandText).PropertyBehavior();
			command.Expect(x => x.CommandType).PropertyBehavior();

			var parameters = MockRepository.GenerateMock<IDataParameterCollection>();
			command.Expect(x => x.Parameters).Return(parameters).Repeat.Any();
			return command;
		}


		public static IDbDataParameter CreateMockParameter(IDbCommand command)
		{
			var parameter = MockRepository.GenerateMock<IDbDataParameter>();
			command.Expect(x => x.CreateParameter()).Return(parameter);
			parameter.Expect(x => x.Size).PropertyBehavior();
			parameter.Expect(x => x.ParameterName).PropertyBehavior();
			parameter.Expect(x => x.Value).PropertyBehavior();
			parameter.Expect(x => x.DbType).PropertyBehavior();
			parameter.Expect(x => x.Direction).PropertyBehavior();

			return parameter;
		}
	}
}
